package com.xiaoxu.intranetweb.util.excel.strategy;

import com.alibaba.excel.write.handler.AbstractSheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;

import java.util.List;

public class CustomSheetWriteHandler1 extends AbstractSheetWriteHandler {
    private List<Integer[]> mergedRegions1;

    public CustomSheetWriteHandler1(List<Integer[]> mergedRegions1) {
        this.mergedRegions1 = mergedRegions1;
    }

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
        Sheet sheet = writeSheetHolder.getSheet();
        for (Integer[] region : mergedRegions1) {
            int firstRow = region[0];
            int lastRow = region[1];

            if (firstRow == lastRow) {
                sheet.addMergedRegionUnsafe(new CellRangeAddress(firstRow, lastRow, 0, 1)); // 合并第一列的单元格
            }
        }
    }
}